package com.liao.ticket.controller;

import com.alibaba.fastjson.JSON;
import com.liao.ticket.dao.pojo.Place;
import com.liao.ticket.service.PlaceService;
import com.liao.ticket.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 接口测试成功
 * 22.10.13 21:26
 * 1.0.0
 */
@RestController
@RequestMapping("place")
public class PlaceController {
    @Autowired
    private PlaceService placeService;

    @GetMapping("list/province")
    public Result allProvince() {
        List<Place> placeList = placeService.allProvince();
        return Result.success(placeList);
    }

    // 通过 省id 查询 省
    @GetMapping("province/{id}")
    public Result oneProvince(@PathVariable Integer id) {
        Place place = placeService.oneProvince(id);
        return Result.success(place);
    }

    // 通过 省id 查询 市列表
    @GetMapping("list/city/{id}")
    public Result listCity(@PathVariable Integer id) {
        List<Place> placeList = placeService.listCity(id);
        return Result.success(placeList);
    }

    // 通过 市id 查询 市
    @GetMapping("city/{id}")
    public Result oneCity(@PathVariable Integer id) {
        Place place = placeService.oneCity(id);
        return Result.success(place);
    }

    // 通过 市id 查询 区/县列表
    @GetMapping("list/county/{id}")
    public Result listCounty(@PathVariable Integer id) {
        List<Place> placeList = placeService.listCounty(id);
        return Result.success(placeList);
    }

    // 通过 区/县id 查询 区/县
    @GetMapping("county/{id}")
    public Result oneCounty(@PathVariable Integer id) {
        Place placeList = placeService.oneCounty(id);
        return Result.success(placeList);
    }

    // 通过 地名 查询 省/市/区县列表
    @PostMapping("list/place")
    public Result listPlace(String name){
        List<Place> placeList = placeService.listPlace(name);
        return Result.success(placeList);
    }
}
